﻿using UnityEngine;
using UnityEngine.SceneManagement;

public class BallUp : MonoBehaviour {

	public int Velocity = 1;	//上升速度
	public bool status = true;	//运动状态
	public GameObject center;
	public LineRenderer line;
	public GameObject music1;
	// Use this for initialization
	void Start () {
		music1 = GameObject.Find ("Music");
		line = GetComponent<LineRenderer> ();
		center = GameObject.Find ("Center");
	}
	
	// Update is called once per frame
	void Update () {
		if (status) {
			transform.Translate (0, Velocity * Time.deltaTime, 0);
			if (transform.position.y >= -2.5) {
				transform.position = new Vector3 (0, -2.5f, 0);
				transform.parent = center.transform;
				music1.SendMessage ("Music1Play");
				status = false;
			}
		}
		else 
		{
			line.SetPosition (1,transform.position);
		}
	}

	void OnTriggerEnter(Collider coll)
	{
		if (coll.CompareTag("Ball")) //标签的比较？
		{
			music1.SendMessage ("Music2Play");
			center.SendMessage ("OnStop");
			Invoke ("OnOver",1f);
		}
	}

	void OnOver()
	{
		SceneManager.LoadScene (2);
	}
}
